package com.atguigu.dao.impl;

import com.atguigu.dao.ProjectModuleDao;
import com.atguigu.dao.ProjectModuleDao;
import com.atguigu.pojo.ProjectModule;

import java.util.List;

public class ProjectModuleDaoImpl extends BaseDao implements ProjectModuleDao {
    @Override
    public int addProjectModule(ProjectModule projectModule) {
        System.out.println("ProjectModuleDaoImpl程序在[" + Thread.currentThread().getName() + "]线程中");
        String sql = "insert into t_projectModule(`id`,`projectId`,`name`,`codeRepository`,`projectModuleTypeId`,`deployPullRootUrl`) values(?,?,?,?,?,?);";
        return update(sql,projectModule.getId(),projectModule.getProjectId(),projectModule.getName(),projectModule.getCodeRepository(),projectModule.getProjectModuleTypeId(),projectModule.getDeployPullRootUrl());
    }
    @Override
    public int updateProjectModule(ProjectModule projectModule) {
        String sql = "update t_projectModule set `projectId`=?, `name`=?,`codeRepository`=?,`projectModuleTypeId`=?,`deployPullRootUrl`=? where id=?";
        return update(sql,projectModule.getProjectId(),projectModule.getName(),projectModule.getCodeRepository(),projectModule.getProjectModuleTypeId(),projectModule.getDeployPullRootUrl(), projectModule.getId());
    }

    @Override
    public int deleteProjectModuleById(String id) {
        String sql = "delete from t_projectModule where id=?";
        return update(sql, id);
    }
    @Override
    public ProjectModule queryProjectModuleByName(String name) {
        String sql = "select `id`,`projectId`,`name`,`codeRepository`,`projectModuleTypeId`,`deployPullRootUrl` from t_projectModule where name=?";
        return queryForOne(ProjectModule.class, sql, name);
    }

    @Override
    public ProjectModule queryProjectModuleById(String id) {
        String sql = "select `id`,`projectId`,`name`,`codeRepository`,`projectModuleTypeId`,`deployPullRootUrl` from t_projectModule where id=?";
        return queryForOne(ProjectModule.class, sql, id);
    }

    @Override
    public List<ProjectModule> queryProjectModules() {
        String sql = "select `id`,`projectId`,`name`,`codeRepository`,`projectModuleTypeId`,`deployPullRootUrl` from t_projectModule";
        return queryForList(ProjectModule.class, sql);
    }

    @Override
    public List<ProjectModule> queryProjectModulesByProjectId(String projectId) {
        String sql = "select `id`,`projectId`,`name`,`codeRepository`,`projectModuleTypeId`,`deployPullRootUrl` from t_projectModule where projectId=?";
        return queryForList(ProjectModule.class, sql,projectId);
    }
    @Override
    public List<ProjectModule> queryProjectModulesByProjectModuleTypeId(String projectModuleTypeId) {
        String sql = "select `id`,`projectId`,`name`,`codeRepository`,`projectModuleTypeId`,`deployPullRootUrl` from t_projectModule where projectModuleTypeId=?";
        return queryForList(ProjectModule.class, sql,projectModuleTypeId);
    }



    @Override
    public List<ProjectModule> queryProjectModulesByProjectIdAndProjectModuleTypeId(String projectId,String projectModuleTypeId) {
        String sql = "select `id`,`projectId`,`name`,`codeRepository`,`projectModuleTypeId`,`deployPullRootUrl` from t_projectModule where projectId=? and projectModuleTypeId=?";
        return queryForList(ProjectModule.class, sql,projectId,projectModuleTypeId);
    }
}
